<?php
include_once($_SERVER['DOCUMENT_ROOT']."/config.php");
//$_SERVER['HTTP_USER_AGENT']
//$_SERVER['HTTP_ACCEPT_LANGUAGE']
//一种语言时zh-cn
//两种语言时zh-CN,en-US;q=0.8
//三种语言时zh-CN,zh-TW;q=0.8,zh;q=0.6
//四种语言时zh-CN,zh-TW;q=0.8,zh;q=0.6,en-US;q=0.4
//五种语言时zh-CN,zh-TW;q=0.8,zh;q=0.6,en-US;q=0.4,es;q=0.2

class check_written_language
{
	public static $written_language_tag_map = array(
		'EN' => 'en-US',
		'EN-US' => 'en-US',
		//'YUE' => 'yue-Hans',
		//'YUE-HANS' => 'yue-Hans',
		//'YUE-HANT' => 'yue-Hant',
		'ZH' => 'zh-Hans-CN',
		'ZH-CN' => 'zh-Hans-CN',
		'ZH-HANS-CN' => 'zh-Hans-CN',
		//'ZH-HANT-HK' => 'zh-Hant-HK',
		//'ZH-HANT-TW' => 'zh-Hant-TW',
		//'ZH-HK' => 'zh-Hant-HK',
		//'ZH-TW' => 'zh-Hant-TW',
	);
	public static function getUserFirstWrittenLanguageTag()
	{
		$lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
		$pos = stripos($lang,",");
		if($pos!==false)//如果有逗号，说明有2种以上
		{
			$first = substr($lang,0,$pos);
		}
		else
		{
			$first = $lang;
		}
		$first_up = strtoupper($first);
		$written_language_tag_map = self::$written_language_tag_map;
		if(!isset($written_language_tag_map[$first_up]))
		{
			return 'zh-Hans-CN';
		}
		else
		{
			return $written_language_tag_map[$first_up];
		}
	}
}

$user_agent['written_language_tag'] = check_written_language::getUserFirstWrittenLanguageTag();
include_once($gDOCUMENT_ROOT_SYSTEM.'written_language/'.$user_agent['written_language_tag'].'/common.php');
?>
